import axios from 'axios';
import qs from 'qs';
import router from "@/router";
// import {
//   Message
// } from 'element-ui';

const service = axios.create({ //http://10.1.8.57:8088/SPI
  // process.env.NODE_ENV === 'development' 来判断是否开发环境

  baseURL: process.env.NODE_ENV === 'development' ? '/api' : '../../kanban',
  timeout: 5000
})
//拦截器
service.interceptors.request.use(config => {
  let user = localStorage.getItem("ivmsInfo");
  if (user != null) {
    let token = JSON.parse(user).token;
    config.headers.common['token'] = token;
  }
  return config;
}, error => {

  return Promise.reject();
})
service.interceptors.response.use(response => {
  if (response.status === 200) {
    //   Message({
    //     message: response.data.message,
    //     type: 'error',
    //     duration: 3000
    //   });
   

     
    return response.data;
  } else {
    Promise.reject();
  }
}, error => {

  return Promise.reject();
})

function httpGet(url, parameter) {

  return service({
    url: url,
    method: 'get',
    params: parameter

  })
}

function httpPost(url, parameter) {
  return service({
    url: url,
    method: 'post',
    data: parameter,
  })
}



export default service;
export {
  httpGet,
  httpPost,
 
};